package com.fire.web.modules.sys.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.fire.common.mybatis.mvc.service.impl.CommonServiceImpl;
import com.fire.common.mybatis.mvc.wrapper.EntityWrapper;
import com.fire.web.modules.sys.entity.Role;
import com.fire.web.modules.sys.entity.UserRole;
import com.fire.web.modules.sys.mapper.RoleMapper;
import com.fire.web.modules.sys.mapper.UserRoleMapper;
import com.fire.web.modules.sys.service.IRoleService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service("roleService")
public class RoleServiceImpl extends CommonServiceImpl<RoleMapper, Role> implements IRoleService {

	@Autowired
	private UserRoleMapper userRoleMapper;
	@Autowired
	private RoleMapper roleMapper;

	@Override
	public List<Role> findListByUserId(String userid) {
		return baseMapper.findRoleByUserId(userid);
	}

	@Override
	public String queryAuthorityByUserId(String userId){
		UserRole qryUserRole = new UserRole();
		qryUserRole.setUserId(userId);
		UserRole userRole = userRoleMapper.selectOne(qryUserRole);
		String roleId = userRole.getRoleId();
		Role qryRole = new Role();
		qryRole.setId(roleId);
		Role role = roleMapper.selectOne(qryRole);
		String authority = role.getCode();
		return authority;
	}

}
